#include<bits/stdc++.h>
using namespace std;

bool check(int x)
{
	int a = x%10;
	x /= 10;
	while(x)
	{
		int t = x%10;
		x /= 10;
		if(t != a)
			return false;
	}
	return true;
}

int getCnt(int x)
{
	int cnt = 0;
	while(x)
	{
		cnt++;
		x /= 10;
	}
	return cnt;
}

int num[] = {0, 1, 11, 111, 1111, 11111, 111111};

int main()
{
	int x;
	while(cin>>x && x >= 0)
	{
		if(check(x))
			cout<<x<<endl;
		else
		{
			int cnt = getCnt(x);
			int dif = num[cnt-1]*9;
			int mn = x-dif;
			int t;
			for(int i = 1;i <= 9;i++)
			{
				t = num[cnt]*i;
				int mid = abs(t-x);
				if(mid < mn)
				{
					mn = abs(t-x);
					dif = t;
				}
				else if(mid == mn)
					dif = max(dif, t);
			}
			cout<<dif<<endl;
		}
	}
	return 0;
}

